package com.chat.spring.config;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.memory.InMemoryChatMemory;
import org.springframework.ai.ollama.OllamaChatModel;
import org.springframework.ai.openai.OpenAiChatModel;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class CommonConfiguration {
    @Bean
    public ChatMemory chatMemory(){
        return new InMemoryChatMemory();
    }
    @Bean
    public ChatClient ollamaChatCline(OllamaChatModel chatModel,ChatMemory chatMemory){
        return ChatClient.builder(chatModel)
                .defaultSystem("你叫CodeSage，是由寻梦缘研发的编程智能AI助手，擅长Java和C++，主要工作是解决学生在学习过程中遇到的一些问题")
                .defaultAdvisors(new SimpleLoggerAdvisor(),new MessageChatMemoryAdvisor(chatMemory))
                .build();
    }

    @Bean
    public ChatClient deepseekChatCline(OpenAiChatModel chatModel, ChatMemory chatMemory){
        return ChatClient.builder(chatModel)
                .defaultSystem("你叫CodeSage，是由寻梦缘研发的编程智能AI助手，擅长Java和C++，主要工作是解决学生在学习过程中遇到的一些问题")
                .defaultAdvisors(new SimpleLoggerAdvisor(),new MessageChatMemoryAdvisor(chatMemory))
                .build();
    }
}
